﻿using System;
using System.Web.Http;
using yiCommerce.Areas.Admin.Models.Products;
using yiCommerce.Core;
using yiCommerce.Core.Helper;
using yiCommerce.Service.Loggings;
using yiCommerce.Service.Products;

namespace yiCommerce.Areas.Admin.Controllers.api
{
    public class ProductSpeficationAttributeInsertRequest
    {
        public int ProductId { get; set; }
        public SpecificationAttributeOptionModel SelectedSpecificationAttributeOption { get; set; }
    }

    public class ProductSpeficationAttributeApiController : ApiController
    {

        private readonly IWorkContext _workContext;
        private IActivityService _activityService;
        private IProductService _productService;

        public ProductSpeficationAttributeApiController(IWorkContext workContext, IActivityService activityService, IProductService productService)
        {
            _workContext = workContext;
            _activityService = activityService;
            _productService = productService;
        }

        public InsertProductPictureResult InsertProductSpeficiationAttribute(ProductSpeficationAttributeInsertRequest request)
        {
            var result = new InsertProductPictureResult();


            try
            {

                _productService.InsertProductSpecificationAttribute(request.ProductId, request.SelectedSpecificationAttributeOption.Id);

                result.Status = "0";

                _activityService.InsertActivity("InsertProductSpeficiationAttribute", JsonHelper.ToJson(request), _workContext.CurrentCustomer);
                return result;
            }
            catch (Exception e)
            {
                result.Status = "1";
                result.Message = e.ToString();
                return result;
            }

            return result;
        }
    }
}
